import requests
from bs4 import BeautifulSoup


def inf():
    model_name = "sys_inf"
    model_function = "数据对接模块，负责启动时对软件的相关信息进行更新操作"
    return model_name, model_function

def fetch_data_optimized():
    try:
        # 优化请求设置，增加超时时间
        response = requests.get(
            "https://gitee.com/lee-guolon/elysium/blob/master/Elysium_database/updata",
            headers={"User-Agent": "Mozilla/5.0"},
            timeout=5,  # 增加超时时间
        )
        response.raise_for_status()

        # 使用 lxml 解析器加速
        soup = BeautifulSoup(response.text, 'lxml')

        textarea = soup.find('textarea', {'id': 'blob_raw'})
        if textarea:
            raw_text = textarea.text.strip()

            # 直接解析数据内容
            lines = raw_text.splitlines()
            version_new = lines[0].replace("最新版本[", "").replace("]", "")
            description_new = lines[1].replace("版本说明[", "").replace("]", "")
            download_link_new = lines[2].replace("下载地址[", "").replace("]", "")

            # 返回三个独立的值
            return version_new, description_new, download_link_new
        else:
            return "Target <textarea> not found"

    except requests.exceptions.RequestException as e:
        return f"An error occurred: {e}"
